#ifndef _RMRACCEL
#define _RMRACCEL
#include "WPILib.h"


class RMRAccel : public Accelerometer
{
public:
	// constructor...
	
	// only constructor allowed is based on an existing AnalogChannel object
	RMRAccel(AnalogChannel *channel);
	
	// methods...

	// return the current accelerometer speed in units of feet/sec
	// found by integrating accelerometer output
	float GetSpeed(void);
	
	// utility routine to set member variables to defaults
	void SetDefaults(void);
	
	// Record a number of samples (CALIBRATION_SAMPLES) for a certain time (CALIBRATION_WAIT)
	// Assume the robot is not accelerating, and use the average of the samples found as the zero point
	void Calibrate(Watchdog &watchdog);
	
	// reset the speed to zero (in case we know the accelerometer isn't moving)
	void ResetSpeed(void);
	
	// Directly get the voltage from the accelerometer
	float GetVoltage(void);
	
	// Return the current acceleration (in terms of g), filtered to reduce noise
	float GetFilteredAccel(void);
	
	
	// constants...
	
	static const float ACCEL_DEADZONE_PAUL = 0.01;
	
	// number of samples to take when calibrating
	static const int CALIBRATION_SAMPLES = 30;
	// amount of time (in seconds) to wait when calibrating
	static const float CALIBRATION_WAIT = 0.05;

	// time in seconds for calibration (after this the watchdog starves and the robot dies)
	static const float MAX_TIME_FOR_CALIBRATE = 3.0;
	
	// default accelerometer filtering gain
	static const float ACCEL_GAIN = .1;
	
private:
	// previous time, used for integration in GetSpeed()
	float m_last_t;
	
	// last computed speed, accessed and computed by GetSpeed()
	float m_last_speed;
	
	// pointer to the analog channel of the accelerometer
	AnalogChannel *m_analogchannel;
	
	// history of filtered acceleration, used by GetFilteredAccel()
	float m_acceleration_filtered;
	
	// Value (0.0 .. 1.0) to control how much smoothing the GetFilteredAccel() function does
	float m_gain;
	
};






#endif
